package com.beaven.model.model.card;

import com.beaven.model.model.base.Author;
import com.beaven.model.model.db.User;
import java.util.Date;

/**
 * author: Beaven
 * time: 2017/5/18 15:21
 *
 * 服务器返回数据
 */

public class UserCard implements Author {

  private String id;
  private String name;

  // 用户关注人的数量
  private int follows;

  // 用户粉丝的数量
  private int following;

  // 我与当前User的关系状态，是否已经是好友
  private boolean isFollow;

  private int categories;

  private String categoryId;

  private boolean isOnline;
  // 用户信息最后的更新时间
  private Date modifyAt;

  private String account;

  private int chatColor;

  @Override public String getId() {
    return id;
  }

  @Override public void setId(String id) {
    this.id = id;
  }

  @Override public String getName() {
    return name;
  }

  @Override public void setName(String name) {
    this.name = name;
  }

  public int getFollows() {
    return follows;
  }

  public void setFollows(int follows) {
    this.follows = follows;
  }

  public int getFollowing() {
    return following;
  }

  public void setFollowing(int following) {
    this.following = following;
  }

  public boolean isFollow() {
    return isFollow;
  }

  public void setFollow(boolean follow) {
    isFollow = follow;
  }

  public int getCategories() {
    return categories;
  }

  public void setCategories(int categories) {
    this.categories = categories;
  }

  public String getCategoryId() {
    return categoryId;
  }

  public void setCategoryId(String categoryId) {
    this.categoryId = categoryId;
  }

  public boolean isOnline() {
    return isOnline;
  }

  public void setOnline(boolean online) {
    isOnline = online;
  }

  public User getUser() {
    return user;
  }

  public void setUser(User user) {
    this.user = user;
  }

  public Date getModifyAt() {
    return modifyAt;
  }

  public String getAccount() {
    return account;
  }

  public void setAccount(String account) {
    this.account = account;
  }

  public void setModifyAt(Date modifyAt) {
    this.modifyAt = modifyAt;
  }

  // 缓存一个对应的User, 不能被GSON框架解析使用
  private transient User user;

  public User build() {
    if (user == null) {
      User user = new User();
      user.setId(id);
      user.setName(name);
      user.setFollow(isFollow);
      user.setFollows(follows);
      user.setFollowing(following);
      user.setModifyAt(modifyAt);
      user.setCategoryId(categoryId);
      user.setOnline(isOnline);
      user.setAccount(account);
      user.setChatColor(chatColor);
      this.user = user;
    }
    return user;
  }

  @Override public String toString() {
    return "UserCard{"
        + "id='"
        + id
        + '\''
        + ", name='"
        + name
        + '\''
        + ", follows="
        + follows
        + ", following="
        + following
        + ", isFollow="
        + isFollow
        + ", categories="
        + categories
        + ", categoryId='"
        + categoryId
        + '\''
        + ", isOnline="
        + isOnline
        + ", modifyAt="
        + modifyAt
        + ", user="
        + user
        + '}';
  }
}
